package middleware

import (
	"github.com/gin-gonic/gin"
	"github.com/google/uuid"
	"xinduobang/stock/common"
)

// LoggerMiddleware 日志中间件
func AddTraceId() gin.HandlerFunc {
	return func(c *gin.Context) {
		traceId := c.GetHeader(common.TRACE_ID)
		if traceId == "" {
			traceId = uuid.New().String()
		}
		c.Header("Traceid", traceId)    // 默认会将首字母大写，后面的字母小写
		c.Set(common.TRACE_ID, traceId) // 将 traceid 存储到 Gin 的上下文中
		c.Next()
		// traceID := c.GetString("traceid")
	}
}
